package com.qls.ali.biz.data.controller;


import com.qls.ali.biz.service.fz.RatesService;
import com.qls.core.dto.BatchPushRatesBody;
import com.qls.core.dto.HtDailyRoom;
import com.qls.core.dto.PushRatesBody;
import com.qls.core.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author yunchao
 */
@RestController
@RequestMapping("rates")
public class RatesController {


    @Autowired
    private RatesService ratesService;


    @PostMapping("push")
    public R push(@RequestBody BatchPushRatesBody batchPushRatesBody) {
        List<PushRatesBody> pushRatesBodies = batchPushRatesBody.getPushRatesBodies();
        Map<Long, List<HtDailyRoom>> map = new HashMap<>();
        Integer storeId = batchPushRatesBody.getStoreId();
        for (PushRatesBody pushRatesBody : pushRatesBodies) {
            map.put(pushRatesBody.getRpCode(), pushRatesBody.getHtDailyRooms());
        }
        ratesService.pushBatch(map, storeId);
        return R.ok();
    }


}
